<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Emplace operations in older compilers</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Boost.Optional">
<link rel="up" href="../dependencies_and_portability.html" title="Dependencies and Portability">
<link rel="prev" href="../dependencies_and_portability.html" title="Dependencies and Portability">
<link rel="next" href="optional_reference_binding.html" title="Optional Reference Binding">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../dependencies_and_portability.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dependencies_and_portability.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="optional_reference_binding.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_optional.dependencies_and_portability.emplace_operations_in_older_compilers"></a><a class="link" href="emplace_operations_in_older_compilers.html" title="Emplace operations in older compilers">Emplace
      operations in older compilers</a>
</h3></div></div></div>
<p>
        <a name="optional_emplace_workaround"></a>Certain constructors and functions
        in the interface of <code class="computeroutput"><span class="identifier">optional</span></code>
        perform a 'perfect forwarding' of arguments:
      </p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span><span class="special">...</span> <span class="identifier">Args</span><span class="special">&gt;</span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_t</span><span class="special">,</span> <span class="identifier">Args</span><span class="special">&amp;&amp;...</span> <span class="identifier">args</span><span class="special">);</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span><span class="special">...</span> <span class="identifier">Args</span><span class="special">&gt;</span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_if_t</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">,</span> <span class="identifier">Args</span><span class="special">&amp;&amp;...</span> <span class="identifier">args</span><span class="special">);</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span><span class="special">...</span> <span class="identifier">Args</span><span class="special">&gt;</span> <span class="keyword">void</span> <span class="identifier">emplace</span><span class="special">(</span><span class="identifier">Args</span><span class="special">&amp;&amp;...</span> <span class="identifier">args</span><span class="special">);</span>
</pre>
<p>
        On compilers that do not support variadic templates, each of these functions
        is substituted with two overloads, one forwarding a single argument, the
        other forwarding zero arguments. This forms the following set:
      </p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">&gt;</span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_t</span><span class="special">,</span> <span class="identifier">Arg</span><span class="special">&amp;&amp;</span> <span class="identifier">arg</span><span class="special">);</span>
<span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_t</span><span class="special">);</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">&gt;</span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_if_t</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">,</span> <span class="identifier">Arg</span><span class="special">&amp;&amp;</span> <span class="identifier">arg</span><span class="special">);</span>
<span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_if_t</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">);</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">&gt;</span> <span class="keyword">void</span> <span class="identifier">emplace</span><span class="special">(</span><span class="identifier">Arg</span><span class="special">&amp;&amp;</span> <span class="identifier">arg</span><span class="special">);</span>
<span class="keyword">void</span> <span class="identifier">emplace</span><span class="special">();</span>
</pre>
<p>
        On compilers that do not support rvalue references, each of these functions
        is substituted with three overloadss: taking <code class="computeroutput"><span class="keyword">const</span></code>
        and non-<code class="computeroutput"><span class="keyword">const</span></code> lvalue reference,
        and third forwarding zero arguments. This forms the following set:
      </p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">&gt;</span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_t</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Arg</span><span class="special">&amp;</span> <span class="identifier">arg</span><span class="special">);</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">&gt;</span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_t</span><span class="special">,</span> <span class="identifier">Arg</span><span class="special">&amp;</span> <span class="identifier">arg</span><span class="special">);</span>
<span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_t</span><span class="special">);</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">&gt;</span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_if_t</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Arg</span><span class="special">&amp;</span> <span class="identifier">arg</span><span class="special">);</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">&gt;</span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_if_t</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">,</span> <span class="identifier">Arg</span><span class="special">&amp;</span> <span class="identifier">arg</span><span class="special">);</span>
<span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_if_t</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">);</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">&gt;</span> <span class="keyword">void</span> <span class="identifier">emplace</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Arg</span><span class="special">&amp;</span> <span class="identifier">arg</span><span class="special">);</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">&gt;</span> <span class="keyword">void</span> <span class="identifier">emplace</span><span class="special">(</span><span class="identifier">Arg</span><span class="special">&amp;</span> <span class="identifier">arg</span><span class="special">);</span>
<span class="keyword">void</span> <span class="identifier">emplace</span><span class="special">();</span>
</pre>
<p>
        This workaround addressess about 40% of all use cases. If this is insufficient,
        you need to resort to using <a class="link" href="../tutorial/in_place_factories.html" title="In-Place Factories">In-Place
        Factories</a>.
      </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2003-2007 Fernando Luis Cacciola Carballal<br>Copyright © 2014-2021 Andrzej Krzemieński<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../dependencies_and_portability.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dependencies_and_portability.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="optional_reference_binding.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
